package callnumber.gtdev5.com.photoVault.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gtdev5.geetolsdk.mylibrary.util.SpUtils;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import callnumber.gtdev5.com.photoVault.R;
import callnumber.gtdev5.com.photoVault.adapter.VipListAdapter;
import callnumber.gtdev5.com.photoVault.base.BaseFragment;
import callnumber.gtdev5.com.photoVault.bean.Gds;
import callnumber.gtdev5.com.photoVault.constants.AppConstans;
import callnumber.gtdev5.com.photoVault.widget.DialogShowMember;

/**
 * Created by cheng
 * PackageName FakeCall_4
 * 2018/8/15 15:49
 */

public class VipFragment extends BaseFragment {
    @BindView(R.id.head_center_title)
    TextView headCenterTitle;
//    @BindView(R.id.txt_vip_time)
//    TextView txtVipTime;
    List<Gds> mList;
    VipListAdapter adapter;

    @BindView(R.id.recy_vip)
    RecyclerView recyclerView;
    @BindView(R.id.bt_bottom)
    Button btn;
    @BindView(R.id.txt_cost)
    TextView txt_costc;
    LinearLayout rvVipTequan;
    Unbinder unbinder;

    @Override
    protected int getLayouId() {
        return R.layout.fragment_vip;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {

    }

    @Override
    protected void initDatas() {
        headCenterTitle.setText("我的会员");
//        if (vip.isIsout()) {
//            text_kait.setText("未开通");
//        } else {
//            text_kait.setText("已开通");
//            txtVipTime.setText("会员到期时间：" + vip.getTime());
//        }

        mList = new ArrayList<>();
        if (DataSupport.findAll(Gds.class) != null) {
            mList = DataSupport.findAll(Gds.class);
            Collections.reverse(mList);
            txt_costc.setText(mList.get(0).getPrice());
//            LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//            layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//            recyclerView.setLayoutManager(layoutManager);
            GridLayoutManager manager = new GridLayoutManager(getActivity(), 1);
            recyclerView.setLayoutManager(manager);
        }
        adapter = new VipListAdapter(getContext(), mList);
        recyclerView.setAdapter(adapter);
        recyclerView.setNestedScrollingEnabled(false);

        adapter.setOnItemClickListener((view, position) -> {
            adapter.setSelectPos(position);
            txt_costc.setText(mList.get(position).getPrice());
            Gds gd = mList.get(position);
            pay(gd.getGid());
        });
        btn.setOnClickListener(v -> {
            pay(adapter.getGid());
        });
    }

    public void onResume() {
        super.onResume();
        updataVip();
    }

    @Override
    protected void initAction() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 101) {
            initDatas();
        }

    }


}
